﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;

namespace Golf.WebUI.AdminShow.CommentLlist
{
    public partial class CommentModify : Golf.WebUI.App_code.ValidateLogin
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int Id = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(Id);
                }
            }
        }

        private void ShowInfo(int Id)
        {
            Golf.BLL.Golf_Comment bll = new Golf.BLL.Golf_Comment();
            Golf.Model.Golf_Comment model = bll.GetModel(Id);
            this.lblId.Text = model.Id.ToString();
            this.txtOrderNumber.Text = model.OrderNumber;
            this.txtUserId.Text = model.UserId.ToString();
            this.txtFristName.Text = model.FristName;
            this.txtLastName.Text = model.LastName;
            this.txtProductId.Text = model.ProductId.ToString();
            this.txtCommentTitle.Text = model.CommentTitle;
            this.txtCommentContent.Text = model.CommentContent;
            this.txtCommentTime.Text = model.CommentTime.ToString();
            this.txtCommentIp.Text = model.CommentIp;
            this.txtCommentScore.Text = model.CommentScore.ToString();
            this.txtCommentNum.Text = model.CommentNum;
            this.chkIsShow.Checked = model.IsShow;

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtOrderNumber.Text.Trim().Length == 0)
            {
                strErr += "订单号不能为空！\\n";
            }
            if (!PageValidate.IsNumber(txtUserId.Text))
            {
                strErr += "会员id	Golf_User表格式错误！\\n";
            }
            if (this.txtFristName.Text.Trim().Length == 0)
            {
                strErr += "姓	Golf_User表不能为空！\\n";
            }
            if (this.txtLastName.Text.Trim().Length == 0)
            {
                strErr += "名	Golf_User表不能为空！\\n";
            }
            if (!PageValidate.IsNumber(txtProductId.Text))
            {
                strErr += "产品id	Golf_Produ格式错误！\\n";
            }
            if (this.txtCommentTitle.Text.Trim().Length == 0)
            {
                strErr += "标题（产品名称）	Golf_P不能为空！\\n";
            }
            if (this.txtCommentContent.Text.Trim().Length == 0)
            {
                strErr += "评论内容不能为空！\\n";
            }
            if (!PageValidate.IsDateTime(txtCommentTime.Text))
            {
                strErr += "评论时间格式错误！\\n";
            }
            if (this.txtCommentIp.Text.Trim().Length == 0)
            {
                strErr += "用户IP不能为空！\\n";
            }
            if (!PageValidate.IsNumber(txtCommentScore.Text))
            {
                strErr += "评论分数格式错误！\\n";
            }
            if (this.txtCommentNum.Text.Trim().Length == 0)
            {
                strErr += "评论次数不能为空！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int Id = int.Parse(this.lblId.Text);
            string OrderNumber = this.txtOrderNumber.Text;
            int UserId = int.Parse(this.txtUserId.Text);
            string FristName = this.txtFristName.Text;
            string LastName = this.txtLastName.Text;
            int ProductId = int.Parse(this.txtProductId.Text);
            string CommentTitle = this.txtCommentTitle.Text;
            string CommentContent = this.txtCommentContent.Text;
            DateTime CommentTime = DateTime.Parse(this.txtCommentTime.Text);
            string CommentIp = this.txtCommentIp.Text;
            int CommentScore = int.Parse(this.txtCommentScore.Text);
            string CommentNum = this.txtCommentNum.Text;
            bool IsShow = this.chkIsShow.Checked;


            Golf.Model.Golf_Comment model = new Golf.Model.Golf_Comment();
            model.Id = Id;
            model.OrderNumber = OrderNumber;
            model.UserId = UserId;
            model.FristName = FristName;
            model.LastName = LastName;
            model.ProductId = ProductId;
            model.CommentTitle = CommentTitle;
            model.CommentContent = CommentContent;
            model.CommentTime = CommentTime;
            model.CommentIp = CommentIp;
            model.CommentScore = CommentScore;
            model.CommentNum = CommentNum;
            model.IsShow = IsShow;

            Golf.BLL.Golf_Comment bll = new Golf.BLL.Golf_Comment();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}